namespace Skymate.Commands
{
    using Abp.Dependency;
    using Abp.Events.Bus;
    using Abp.Logging;

    using Skymate.Lyjt.Core;

    using SuperSocket.SocketBase.Command;

    public abstract class BaseLightCommand
    : ICommand<LightAppSession, SemaphoreRequestInfo>
    {
        
        protected byte Option { get; }

        protected byte Object { get; }

        protected IProtocolAnalysis ProtocolAnalysis { get; private set; }
        
        protected BaseLightCommand(byte option,byte obj)
        {
            this.Object = obj;
            this.Option = option;

            this.ProtocolAnalysis = IocManager.Instance.Resolve<IProtocolAnalysis>();
            
        }

        protected void ShowLog(string ip,string message, string data = "")
        {
            EventBus.Default.Trigger(
                new ShowLogEvent(ip,
                message,data));
            LogHelper.Logger.Debug($"信息:{message},数据:{data}");
        }

        public abstract void ExecuteCommand(LightAppSession session, SemaphoreRequestInfo requestInfo);

        public string Name
        {
            get
            {
                return this.Option.ToString("X2")
                       + this.Object.ToString("X2");
            }
        }
    }
}